package com.example.service.impl;

import ch.qos.logback.classic.Logger;
import com.example.entity.IndexEcharts;
import com.example.entity.authority.Party;
import com.example.mapp.IndexEchartsMapp;
import com.example.mapp.PartyMapp;
import com.example.mapp.StatisticsMapp;
import com.example.service.StatisticsService;
import com.example.util.ResultUtil;
import com.example.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by douyx on 2017/11/13.
 */
@Service
public class StatisticsServiceImpl implements StatisticsService {

	private final static Logger logger = (Logger) LoggerFactory.getLogger(StatisticsServiceImpl.class);

	@Autowired
	private StatisticsMapp statisticsMapp;

	@Autowired
	private PartyMapp partyMapp;

	@Autowired
	IndexEchartsMapp indexEchartsMapp;

	/**
	 * 查询待通知的物业人员列表
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> findNotice() {
		List<Map<String, Object>> list = new ArrayList<>();
		try {
			list = statisticsMapp.findNotice();
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 辖区内电梯各项统计
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countEleNum(Map param) {
		Map<String, Object> map = new HashMap<>();
		try {
			if (param == null) {
				throw new Exception("参数不能为空");
			}
			String partyId = param.get("partyId").toString();
			if (param.get("partyLevel") != null && "1".equals(param.
					get("partyLevel").toString())) {   // 1代表市局
				map = statisticsMapp.countEleNumCity(partyId);
			} else { // 区和分区
				map = statisticsMapp.countEleNumArea(partyId);
			}
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.toString(), null);
		}
		return ResultUtil.returnSuccess("成功", map);
	}

	/**
	 * 辖区内电梯数量分布
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countNumDistrib(Map param) {
		List<Map<String, Object>> list = new ArrayList<>();
		try {
			if (param == null) {
				throw new Exception("参数不能为空");
			}
			String partyId = param.get("partyId").toString();
			if (param.get("partyLevel") != null && "1".equals(param.
					get("partyLevel").toString())) {  // 1代表市局
				//获取局
				List<Party> partys = partyMapp.decideBranchInfo(partyId);
				for (Party party : partys) {
					Map<String, Object> map = partyMapp.querysum(party.getId());
					if (map == null) {
						map = new HashMap<>();
						map.put("elevatorNum", 0);
						map.put("eleStopNum", 0);
						map.put("eleUsedNum", 0);
					}
					map.put("partyName", party.getPartyName());
					list.add(map);
				}
			} else { // 区和分区
				List<Party> partys = partyMapp.decideByPartyLevel(partyId);
				for (Party party : partys) {
					Map<String, Object> map = partyMapp.querysumInId(party.getId());
					if (map == null) {
						map = new HashMap<>();
						map.put("elevatorNum", 0);
						map.put("eleStopNum", 0);
						map.put("eleUsedNum", 0);
					}
					map.put("partyName", party.getPartyName());
					list.add(map);
				}
			}
			/*id = getPartyId(id);
			inMap.put("id", id);*/
			/*list = statisticsMapp.countNumDistrib(inMap);*/

			if (list != null && list.size() > 0) {

				List<String> nameList = new ArrayList<>();
				List<IndexEcharts> indexs = indexEchartsMapp.findList();
				if(indexs !=null && indexs.size()>0){
					for(IndexEcharts entry:indexs){
						nameList.add(entry.getKeyName());
					}
				}

				for (Map<String, Object> entryMap : list) {
					String partyName = (String) entryMap.get("partyName");
					if (StringUtil.isNotBlank(partyName)) {
						if(nameList !=null && nameList.size()>0){
							String newPartyName = StringUtil.changeName(nameList, partyName);
							entryMap.put("newPartyName", newPartyName);
						}
					}
				}
			}
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 辖区内电梯类型分布
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countTypeDistrib() {
		List<Map<String, Object>> list = new ArrayList<>();
		try {
			list = statisticsMapp.countTypeDistrib();
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 辖区内电梯年限分布
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countYearDistrib(Map map) {
		Map<String, Object> maps = new HashMap<>();
		try {
			if (map != null && map.size() > 0) {
				int integer = (int) map.get("id");
				String id = String.valueOf(integer);

				if (map.get("partyLevel") != null && "1".equals(map.
						get("partyLevel").toString())) {   // 1 代表市局
					maps = statisticsMapp.countYearDistribCity(id);
				}else{
					maps = statisticsMapp.countYearDistribArea(id);
				}
			}
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", maps);
	}

	/**
	 * 辖区内保障力量分布
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countOperDistrib(Map map) {
		Map<String, Object> maps = new HashMap<>();
		try {
			if (map != null && map.size() > 0) {
				int integer = (int) map.get("id");
				String id = String.valueOf(integer);


				if (map.get("partyLevel") != null && "1".equals(map.
						get("partyLevel").toString())) {   // 1 代表市局
					maps = statisticsMapp.countOperDistribCity(id);
				}else{
					maps = statisticsMapp.countOperDistribArea(id);
				}
			}
			/*map = statisticsMapp.countOperDistrib();*/
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", maps);
	}

	/**
	 * 辖区内各项安全状况统计
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countSafeNum() {
		Map<String, Object> map = new HashMap<>();
		try {
			map = statisticsMapp.countSafeNum();
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", map);
	}

	/**
	 * 电梯安全保障工作落实情况
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countMaintRepairNum(Map param) {
		Map<String, Object> map = new HashMap<>();
		try {
			if (param != null && param.size() > 0) {
				int integer = (int) param.get("id");
				String id = String.valueOf(integer);
				if (param.get("partyLevel") != null && "1".equals(param.
						get("partyLevel").toString())) {   // 1 代表市局
					map = statisticsMapp.countMaintRepairNum();
				}else{
					map = statisticsMapp.countMaintRepairNumArea(id);
					// 查询区局下面的所有电梯Id
					List<String> eleList = statisticsMapp.findElevatorList(id);
					int dayInspNum = 0;
					int quarterInspNum = 0;
					int yearInspNum = 0;
					// 查询每天的
					List<String> dayList =  statisticsMapp.countMaintRepairNumDay();
					if (dayList != null) {
						for (String obj : dayList) {
							if (eleList.contains(obj)) {
								dayInspNum++;
							}
						}
					}
					// 查询本季度的
					List<String> quarterList =  statisticsMapp.countMaintRepairNumQuarter();
					if (quarterList != null) {
						for (String obj : quarterList) {
							if (eleList.contains(obj)) {
								quarterInspNum++;
							}
						}
					}
					// 查询本年的
					List<String> yearList =  statisticsMapp.countMaintRepairNumYear();
					if (yearList != null) {
						for (String obj : yearList) {
							if (eleList.contains(obj)) {
								yearInspNum++;
							}
						}
					}
					map.put("dayInspNum",dayInspNum);
					map.put("quarterInspNum",quarterInspNum);
					map.put("yearInspNum",yearInspNum);
				}
			}
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", map);
	}

	/**
	 * 电梯事故隐患排除情况
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countRepairNum(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		try {
		    // 判断是市还是局
            String limit = decideInfo(id);
            if ("0".equals(limit)) {
                // 0市
                list = statisticsMapp.countRepairNumCity(id);
            } else {
                // 1、2 局和分局看局
                if ("2".equals(limit)) {
                    id = partyMapp.infoById(id).getParentId();
                }
                list = statisticsMapp.countRepairNumArea(id);
            }
			List<String> nameList = new ArrayList<>();
			List<IndexEcharts> indexs = indexEchartsMapp.findList();
			if(indexs !=null && indexs.size()>0){
				for(IndexEcharts entry:indexs){
					nameList.add(entry.getKeyName());
				}
			}

			if (list != null && list.size() > 0) {
				for (Map<String, Object> entryMap : list) {
					String partyName = (String) entryMap.get("partyName");
					if (StringUtil.isNotBlank(partyName)) {
						if(nameList !=null && nameList.size()>0){
							String newPartyName = StringUtil.changeName(nameList, partyName);
							entryMap.put("newPartyName", newPartyName);
						}
					}
				}
			}

		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 电梯安全保障工作超期情况
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countMaintNum(Map param) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		try {
			int integer = (int) param.get("id");
			String id = String.valueOf(integer);
			if (param.get("partyLevel") != null && "1".equals(param.
					get("partyLevel").toString())) {   // 1 代表市局
				list = statisticsMapp.countMaintNum(inMap);
			}else{
				list = statisticsMapp.countMaintNum2(id);
			}
			List<String> nameList = new ArrayList<>();
			List<IndexEcharts> indexs = indexEchartsMapp.findList();
			if(indexs !=null && indexs.size()>0){
				for(IndexEcharts entry:indexs){
					nameList.add(entry.getKeyName());
				}
			}

			if (list != null && list.size() > 0) {
				for (Map<String, Object> entryMap : list) {
					String partyName = (String) entryMap.get("partyName");
					if (StringUtil.isNotBlank(partyName)) {
						if(nameList !=null && nameList.size()>0){
							String newPartyName = StringUtil.changeName(nameList, partyName);
							entryMap.put("newPartyName", newPartyName);
						}
					}
				}
			}

		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 获取年度统计数据
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countQuartz(Map<String, Object> param) {
		Map<String, Object> map = new HashMap<String, Object>();
		String id =  param.get("id")+"";
		try {
			id = getPartyId(id);
			param.put("id", id);
			List<Map<String, Object>> feedbackRescueList = statisticsMapp.selectImplementation1(param);
			List<Map<String, Object>> maintInspList = statisticsMapp.selectImplementation2(param);
			List<Map<String, Object>> repairList = statisticsMapp.selectRepair(param);
			List<Map<String, Object>> maintList = statisticsMapp.selectMaintOvertime(param);
			List<Map<String, Object>> checkList = statisticsMapp.selectCheckOvertime(param);
			map.put("feedbackRescueList", feedbackRescueList);
			map.put("maintInspList", maintInspList);
			map.put("repairList", repairList);
			map.put("maintList", maintList);
			map.put("checkList", checkList);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", map);
	}

	/**
	 * 记录检验超期电梯信息
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> recordOvertimeEle(Map<String, Object> param) {
		try {
			statisticsMapp.insertCheckOvertime(param);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", null);
	}

	private String getPartyId(String id) throws Exception {
		List<Party> partys = partyMapp.queryByPartyIdList(id);
		for (Party party : partys) {
			if ("1".equals(party.getPartyType()) || "2".equals(party.getPartyType())) {
				id = partyMapp.queryById(id).getParentId();
				break;
			}
		}
		return id;
	}

	/**
	 * 查询电梯，投诉，维保等年度总数量
	 * 
	 * @param id
	 * @return
	 */
	@Override
	public Map<String, Object> findCountCount(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.findCountCount(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 辖区内电梯的总数量(物业)
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countElevatorNum(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countElevatorNum(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 辖区内电梯的总数量(维保)
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countEleMaintNum(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countEleMaintNum(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 不同类型电梯数量占比
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countEleTypeNum(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countEleTypeNum(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 使用年限达10年以上电梯数量
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countEleLifeNumOlder(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countEleLifeNumOlder(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 使用年限达10年以下电梯数量
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countEleLifeNumYounger(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countEleLifeNumYounger(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 本帐户辖区维保单位数量
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countMaintCompany(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countMaintCompany(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 本帐户辖区使用单位数量
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countUseCompany(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countUseCompany(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 各单位 资质 数量 及 占比
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countCompanyQuali(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countCompanyQuali(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 各星级 维保单位总数及占比
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countStarCompany(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countStarCompany(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 本帐户辖区安全责任主体单位各类型技术人员持证数量
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countTechmanCompany(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countTechmanCompany(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 乘客投诉处理的反馈 率
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countFeedbackRio(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countFeedbackRio(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 本帐户辖区整体维保准时率、各类型周期性维保的平均时长
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countMaint(String id) {
		Map<String, Object> map = new HashMap<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			List<Map<String, Object>> list = statisticsMapp.countMaintInTime(inMap);
			map.put("maintInTime", list);
			List<Map<String, Object>> usedTimeList = statisticsMapp.countTypeMaintTime(inMap);
			map.put("maintTime", usedTimeList);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", map);
	}

	/**
	 * (按月)本帐户辖区周期内整体召修/维修落实率
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countRepair(String id, String reportDate) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		inMap.put("reportDate", reportDate);
		try {
			list = statisticsMapp.countRepair(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 本帐户辖区周期内现场应急救援累计数
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countRescue(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countRescue(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 使用单位（物业）应急救援演练总次数
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countRescueDrill(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countRescueDrill(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 检验机构数量
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countCheckOrgNum(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countCheckOrgNum(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 使用单位统计数量
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countUserNum(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countUserNum(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 维保单位数量
	 *
	 * @return
	 */
	@Override
	public Map<String, Object> findMaintCount(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.findMaintCount(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 使用单位（物业）过期电梯数
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countOvertimeElevator(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countOvertimeElevator(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 年度乘客投诉处理的反馈 率
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countFeedbackYear(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countFeedbackYear(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 本区域 使用单位各资质数量，汇总统计
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countUsedZz(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countUsedZz(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 本区域 维保单位各资质数量，汇总统计
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countMaintZz(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countMaintZz(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 辖区内 各类 应急救援发生的次数
	 * 
	 * @return
	 */
	@Override
	public Map<String, Object> countRescueNum(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.countRescueNum(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}

	/**
	 * 维保单位今日维保记录
	 *
	 * @return
	 */
	@Override
	public Map<String, Object> findTodayMaint(String id) {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> inMap = new HashMap<String, Object>();
		inMap.put("id", id);
		try {
			list = statisticsMapp.findTodayMaint(inMap);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return ResultUtil.returnError(e.getMessage(), null);
		}
		return ResultUtil.returnSuccess("成功", list);
	}


	/**
	 * 获取是否是分局信息
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public String decideInfo(String id) {
		String limit = "0";
		// 判断市或者局  通过传入Id判断  0是市级 1是局级 2 是分局
		List<Party> partys = partyMapp.decideBranchInfo(id);
		if (partys != null && partys.size() > 0) {
			List<Party> partyList = partyMapp.decideForEach(id);
			if (partyList != null && partyList.size() > 0) {
				limit = "0";
			} else {
				// 此时为局
				limit = "1";
			}
		} else {
			limit = "2";
		}
		return limit;
	}
}
